package com.twl.app.base.bo.salarysumreport;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Future;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.twl.app.base.ctrl.GetSalarySum;
import com.twl.app.base.entity.Bfsalary;
import com.twl.app.base.entity.Dispatchmanger;
import com.twl.app.base.entity.Dutyback;
import com.twl.app.base.entity.Dutymoney;
import com.twl.app.base.entity.Dutysendmoney;
import com.twl.app.base.entity.Leavebmoney;
import com.twl.app.base.entity.Loyalward;
import com.twl.app.base.entity.MinMoney;
import com.twl.app.base.entity.Moneyadjust;
import com.twl.app.base.entity.Overtimemeals;
import com.twl.app.base.entity.Overtimemoney;
import com.twl.app.base.entity.Personalduty;
import com.twl.app.base.entity.Personalmoney;
import com.twl.app.base.entity.SalSalaryData;
import com.twl.app.base.entity.SalSocialAdjust;
import com.twl.app.base.entity.SalarySumReport;
import com.twl.app.base.entity.Secureunit;
import com.twl.app.base.entity.Shiftallowance;
import com.twl.app.base.entity.Solidmoney;
import com.twl.app.base.entity.Tradecost;
import com.twl.app.base.entity.Uemp;
import com.twl.common.constant.SalConstant;
import com.twl.core.framework.dao.WSHibernateDaoSupportProxy;
import com.twl.core.framework.page.ExpResult;
import com.twl.core.framework.page.Page;
import com.twl.core.framework.page.Result;

/**
 * 薪资报表
 * @author Val
 *
 */
@Transactional
@Service
public class SalarySumReportService {
	public Logger log = Logger.getLogger(SalarySumReportService.class);

	@Autowired
	private ThreadPoolTaskExecutor threadPoolTaskExecutor;

	@Autowired
	private WSHibernateDaoSupportProxy wSHibernateDaoSupportProxy;

	/**
	 * 查询卡中心工资明细及报表数据汇总
	 * 
	 * @param hql
	 * @param page
	 * @return
	 * @throws ParseException
	 */
	public Result querySalarySumReport(Map<String, Object> params) {

		Page page = (Page) params.get("page");

		Result uempResult = wSHibernateDaoSupportProxy.getListByPage(getUempHql(params), page);
		// 返回的页面信息
		Page queryPage = uempResult.getPage();

		@SuppressWarnings("unchecked")
		List<Uemp> uempList = uempResult.getContent();

		return new Result(queryPage, getSalarySumReportList(uempList, params));
	}

	/**
	 * 导出卡中心工资明细及报表数据汇总
	 * 
	 * @param hql
	 * @param page
	 * @return
	 * @throws ParseException
	 */
	public ExpResult expSalarySumReport(Map<String, Object> params) {

		Page page = (Page) params.get("page");

		ExpResult uempResult = wSHibernateDaoSupportProxy.getExpListByPage(getUempHql(params), page);

		// 返回的页面信息
		Page queryPage = uempResult.getPage();

		@SuppressWarnings("unchecked")
		List<Uemp> uempList = uempResult.getContent();
		@SuppressWarnings("unchecked")
		List<Uemp> uempExpList = uempResult.getExpContent();
		return new ExpResult(queryPage, getSalarySumReportList(uempList, params), getSalarySumReportList(uempExpList, params));
	}

	/**
	 * 获取员工表SQL
	 * 
	 * @param params
	 * @return
	 */
	private String getUempHql(Map<String, Object> params) {

		StringBuffer uempHql = new StringBuffer("from Uemp where delstaff = '" + SalConstant.NOT_DELETE + "' ");
		String did = params.get("did") == null ? "" : String.valueOf(params.get("did"));
		if (StringUtils.isNotBlank(did)) {
			uempHql.append(" and did ='").append(did).append("' ");
		}

		String card = params.get("card") == null ? "" : String.valueOf(params.get("card"));
		if (StringUtils.isNotBlank(card)) {
			uempHql.append(" and card like'%'||'").append(card).append("'||'%' ");
		}
		String staffint = params.get("staffint") == null ? "" : String.valueOf(params.get("staffint"));
		if (StringUtils.isNotBlank(staffint)) {
			uempHql.append(" and staffint like'%'||'").append(staffint).append("'||'%' ");
		}
		String staffname = params.get("staffname") == null ? "" : String.valueOf(params.get("staffname"));
		if (StringUtils.isNotBlank(staffname)) {
			uempHql.append(" and staffname like'%'||'").append(staffname).append("'||'%' ");
		}
		String dateentry = params.get("dateentry") == null ? "" : String.valueOf(params.get("dateentry"));
		if (StringUtils.isNotBlank(dateentry)) {
			uempHql.append(" and dateentry like'%'||'").append(dateentry).append("'||'%' ");
		}
		String datedimi = params.get("datedimi") == null ? "" : String.valueOf(params.get("datedimi"));
		if (StringUtils.isNotBlank(datedimi)) {
			uempHql.append(" and datedimi like'%'||'").append(datedimi).append("'||'%' ");
		}
		String dept = params.get("dept") == null ? "" : String.valueOf(params.get("dept"));
		if (StringUtils.isNotBlank(dept)) {
			uempHql.append(" and dept like'%'||'").append(dept).append("'||'%' ");
		}
		String tean = params.get("tean") == null ? "" : String.valueOf(params.get("tean"));
		if (StringUtils.isNotBlank(tean)) {
			uempHql.append(" and tean like'%'||'").append(tean).append("'||'%' ");
		}
		String cardlevel = params.get("cardlevel") == null ? "" : String.valueOf(params.get("cardlevel"));
		if (StringUtils.isNotBlank(cardlevel)) {
			uempHql.append(" and cardlevel like'%'||'").append(cardlevel).append("'||'%' ");
		}
		String grade = params.get("grade") == null ? "" : String.valueOf(params.get("grade"));
		if (StringUtils.isNotBlank(grade)) {
			uempHql.append(" and grade like'%'||'").append(grade).append("'||'%' ");
		}
		String jobgrade = params.get("jobgrade") == null ? "" : String.valueOf(params.get("jobgrade"));
		if (StringUtils.isNotBlank(jobgrade)) {
			uempHql.append(" and jobgrade like'%'||'").append(jobgrade).append("'||'%' ");
		}
		String stafftype = params.get("stafftype") == null ? "" : String.valueOf(params.get("stafftype"));
		if (StringUtils.isNotBlank(stafftype)) {
			uempHql.append(" and stafftype like'%'||'").append(stafftype).append("'||'%' ");
		}

		String stafftypes = params.get("stafftypes") == null ? "" : String.valueOf(params.get("stafftypes"));
		if (StringUtils.isNotBlank(stafftypes)) {
			uempHql.append(" and stafftypes like'%'||'").append(stafftypes).append("'||'%' ");
		}
		String jobsort = params.get("jobsort") == null ? "" : String.valueOf(params.get("jobsort"));
		if (StringUtils.isNotBlank(jobsort)) {
			uempHql.append(" and jobsort like'%'||'").append(jobsort).append("'||'%' ");
		}
		String commission = params.get("commission") == null ? "" : String.valueOf(params.get("commission"));
		if (StringUtils.isNotBlank(commission)) {
			uempHql.append(" and commission like'%'||'").append(commission).append("'||'%' ");
		}
		String assailedcom = params.get("assailedcom") == null ? "" : String.valueOf(params.get("assailedcom"));
		if (StringUtils.isNotBlank(assailedcom)) {
			uempHql.append(" and assailedcom like'%'||'").append(assailedcom).append("'||'%' ");
		}
		String costcentre = params.get("costcentre") == null ? "" : String.valueOf(params.get("costcentre"));
		if (StringUtils.isNotBlank(costcentre)) {
			uempHql.append(" and costcentre like'%'||'").append(costcentre).append("'||'%' ");
		}
		return uempHql.toString();
	}

	/**
	 * 获得组装后的结果
	 * 
	 * @param uempList
	 * @param params
	 * @param countDownLatch
	 * @return
	 */
	private List<SalarySumReport> getSalarySumReportList(List<Uemp> uempList, Map<String, Object> params) {
		//计数器
		CountDownLatch countDownLatch = new CountDownLatch(19);
		// 返回的数据
		List<SalarySumReport> salarySumReportList = new ArrayList<SalarySumReport>();

		// StringBuffer companybHql = new StringBuffer("from Companyb ");
		StringBuffer minMoneyHql = new StringBuffer("from MinMoney ");
		StringBuffer dispatchmangerHql = new StringBuffer("from Dispatchmanger ");
		StringBuffer overtimemoneyHql = new StringBuffer("from Overtimemoney ");
		StringBuffer overtimemealsHql = new StringBuffer("from Overtimemeals ");
		StringBuffer moneyadjustHql = new StringBuffer("from Moneyadjust ");
		StringBuffer tradecostHql = new StringBuffer("from Tradecost ");
		StringBuffer dutybackHql = new StringBuffer("from Dutyback ");
		StringBuffer personaldutyHql = new StringBuffer("from Personalduty ");
		StringBuffer leavebmoneyHql = new StringBuffer("from Leavebmoney ");
		StringBuffer loyalwardHql = new StringBuffer("from Loyalward ");
		StringBuffer salSocialAdjustHql = new StringBuffer("from SalSocialAdjust ");
		StringBuffer salSalaryDataHql = new StringBuffer("from SalSalaryData ");
		StringBuffer solidmoneyHql = new StringBuffer("from Solidmoney ");
		StringBuffer dutymoneyHql = new StringBuffer("from Dutymoney ");
		StringBuffer bfsalaryHql = new StringBuffer("from Bfsalary ");
		StringBuffer shiftallowanceHql = new StringBuffer("from Shiftallowance ");
		StringBuffer personalmoneyHql = new StringBuffer(" from Personalmoney ");
		StringBuffer secureunitHql = new StringBuffer(" from Secureunit ");
		StringBuffer dutysendmoneyHql = new StringBuffer(" from Dutysendmoney ");

		String period = params.get("period") == null ? "" : String.valueOf(params.get("period"));

		if (SalConstant.REGULAR_EMP.equals(params.get("stafftype"))) {
			period = getNextMonth(period);
		}

		if (StringUtils.isNotBlank(period)) {
			minMoneyHql.append(" where datemoney ='").append(period).append("' ");
			dispatchmangerHql.append(" where datemoney ='").append(period).append("' ");
			overtimemoneyHql.append(" where datemoney ='").append(period).append("' ");
			overtimemealsHql.append(" where datemoney ='").append(period).append("' ");
			moneyadjustHql.append(" where datemoney ='").append(period).append("' ");
			tradecostHql.append(" where datemoney ='").append(period).append("' ");
			dutybackHql.append(" where datemoney ='").append(period).append("' ");
			personaldutyHql.append(" where datemoney ='").append(period).append("' ");
			leavebmoneyHql.append(" where datemoney ='").append(period).append("' ");
			loyalwardHql.append(" where datemoney ='").append(period).append("' ");
			salSocialAdjustHql.append(" where isDelete = '").append(SalConstant.NOT_DELETE).append("' and period ='").append(period).append("' ");
			salSalaryDataHql.append(" where isDelete = '").append(SalConstant.NOT_DELETE).append("' and period ='").append(period).append("' ");
			solidmoneyHql.append(" where datemoney ='").append(period).append("' ");
			dutymoneyHql.append(" where datemoney ='").append(period).append("' ");
			bfsalaryHql.append(" where datemoney ='").append(period).append("' ");
			shiftallowanceHql.append(" where datemoney ='").append(period).append("' ");
			personalmoneyHql.append(" where datemoney ='").append(period).append("' ");
			secureunitHql.append(" where datemoney ='").append(period).append("' ");
			dutysendmoneyHql.append(" where datemoney ='").append(period).append("' ");
		}

		// GetSalarySum<Companyb> companybCall = new
		// GetSalarySum<Companyb>(Companyb.class,companybHql.toString(),
		// countDownLatch);
		GetSalarySum<MinMoney> minMoneyCall = new GetSalarySum<MinMoney>(MinMoney.class, minMoneyHql.toString(), countDownLatch);
		GetSalarySum<Dispatchmanger> dispatchmangerCall = new GetSalarySum<Dispatchmanger>(Dispatchmanger.class, dispatchmangerHql.toString(), countDownLatch);
		GetSalarySum<Overtimemoney> overtimemoneyCall = new GetSalarySum<Overtimemoney>(Overtimemoney.class, overtimemoneyHql.toString(), countDownLatch);
		GetSalarySum<Overtimemeals> overtimemealsCall = new GetSalarySum<Overtimemeals>(Overtimemeals.class, overtimemealsHql.toString(), countDownLatch);
		GetSalarySum<Moneyadjust> moneyadjustCall = new GetSalarySum<Moneyadjust>(Moneyadjust.class, moneyadjustHql.toString(), countDownLatch);
		GetSalarySum<Tradecost> tradecostCall = new GetSalarySum<Tradecost>(Tradecost.class, tradecostHql.toString(), countDownLatch);
		GetSalarySum<Dutyback> dutybackCall = new GetSalarySum<Dutyback>(Dutyback.class, dutybackHql.toString(), countDownLatch);
		GetSalarySum<Personalduty> personaldutyCall = new GetSalarySum<Personalduty>(Personalduty.class, personaldutyHql.toString(), countDownLatch);
		GetSalarySum<Leavebmoney> leavebmoneyCall = new GetSalarySum<Leavebmoney>(Leavebmoney.class, leavebmoneyHql.toString(), countDownLatch);
		GetSalarySum<Loyalward> loyalwardCall = new GetSalarySum<Loyalward>(Loyalward.class, loyalwardHql.toString(), countDownLatch);
		GetSalarySum<SalSocialAdjust> salSocialAdjustCall = new GetSalarySum<SalSocialAdjust>(SalSocialAdjust.class, salSocialAdjustHql.toString(), countDownLatch);
		GetSalarySum<SalSalaryData> salSalaryDataCall = new GetSalarySum<SalSalaryData>(SalSalaryData.class, salSalaryDataHql.toString(), countDownLatch);
		GetSalarySum<Solidmoney> solidmoneyCall = new GetSalarySum<Solidmoney>(Solidmoney.class, solidmoneyHql.toString(), countDownLatch);
		GetSalarySum<Dutymoney> dutymoneyCall = new GetSalarySum<Dutymoney>(Dutymoney.class, dutymoneyHql.toString(), countDownLatch);
		GetSalarySum<Bfsalary> bfsalaryCall = new GetSalarySum<Bfsalary>(Bfsalary.class, bfsalaryHql.toString(), countDownLatch);
		GetSalarySum<Shiftallowance> shiftallowanceCall = new GetSalarySum<Shiftallowance>(Shiftallowance.class, shiftallowanceHql.toString(), countDownLatch);
		GetSalarySum<Personalmoney> personalmoneyCall = new GetSalarySum<Personalmoney>(Personalmoney.class, personalmoneyHql.toString(), countDownLatch);
		GetSalarySum<Secureunit> secureunitCall = new GetSalarySum<Secureunit>(Secureunit.class, secureunitHql.toString(), countDownLatch);
		GetSalarySum<Dutysendmoney> dutysendmoneyCall = new GetSalarySum<Dutysendmoney>(Dutysendmoney.class, dutysendmoneyHql.toString(), countDownLatch);

		try {
			// Future<Map<String,Uemp>> uempFuture = executor.submit(uempCall);
			// Future<Map<String, Companyb>> companybFuture =
			// threadPoolTaskExecutor.submit(companybCall);
			Future<Map<String, MinMoney>> minMoneyFuture = threadPoolTaskExecutor.submit(minMoneyCall);
			Future<Map<String, Dispatchmanger>> dispatchmangerFuture = threadPoolTaskExecutor.submit(dispatchmangerCall);
			Future<Map<String, Overtimemoney>> overtimemoneyFuture = threadPoolTaskExecutor.submit(overtimemoneyCall);
			Future<Map<String, Overtimemeals>> overtimemealsFuture = threadPoolTaskExecutor.submit(overtimemealsCall);
			Future<Map<String, Moneyadjust>> moneyadjustFuture = threadPoolTaskExecutor.submit(moneyadjustCall);
			Future<Map<String, Tradecost>> tradecostFuture = threadPoolTaskExecutor.submit(tradecostCall);
			Future<Map<String, Dutyback>> dutybackFuture = threadPoolTaskExecutor.submit(dutybackCall);
			Future<Map<String, Personalduty>> personaldutyFuture = threadPoolTaskExecutor.submit(personaldutyCall);
			Future<Map<String, Leavebmoney>> leavebmoneyFuture = threadPoolTaskExecutor.submit(leavebmoneyCall);
			Future<Map<String, Loyalward>> loyalwardFuture = threadPoolTaskExecutor.submit(loyalwardCall);
			Future<Map<String, SalSocialAdjust>> salSocialAdjustFuture = threadPoolTaskExecutor.submit(salSocialAdjustCall);
			Future<Map<String, SalSalaryData>> salSalaryDataFuture = threadPoolTaskExecutor.submit(salSalaryDataCall);
			Future<Map<String, Solidmoney>> solidmoneyFuture = threadPoolTaskExecutor.submit(solidmoneyCall);
			Future<Map<String, Dutymoney>> dutymoneyFuture = threadPoolTaskExecutor.submit(dutymoneyCall);
			Future<Map<String, Bfsalary>> bfsalaryFuture = threadPoolTaskExecutor.submit(bfsalaryCall);
			Future<Map<String, Shiftallowance>> shiftallowanceFuture = threadPoolTaskExecutor.submit(shiftallowanceCall);
			Future<Map<String, Personalmoney>> personalmoneyFuture = threadPoolTaskExecutor.submit(personalmoneyCall);
			Future<Map<String, Secureunit>> secureunitFuture = threadPoolTaskExecutor.submit(secureunitCall);
			Future<Map<String, Dutysendmoney>> dutysendmoneyFuture = threadPoolTaskExecutor.submit(dutysendmoneyCall);
			countDownLatch.await();
			// Map<String,Uemp> uempMap = uempFuture.get();
			// Map<String, Companyb> companybMap = companybFuture.get();
			Map<String, MinMoney> minMoneyMap = minMoneyFuture.get();
			Map<String, Dispatchmanger> dispatchmangerMap = dispatchmangerFuture.get();
			Map<String, Overtimemoney> overtimemoneyMap = overtimemoneyFuture.get();
			Map<String, Overtimemeals> overtimemealsMap = overtimemealsFuture.get();
			Map<String, Moneyadjust> moneyadjustMap = moneyadjustFuture.get();
			Map<String, Tradecost> tradecostMap = tradecostFuture.get();
			Map<String, Dutyback> dutybackMap = dutybackFuture.get();
			Map<String, Personalduty> personaldutyMap = personaldutyFuture.get();
			Map<String, Leavebmoney> leavebmoneyMap = leavebmoneyFuture.get();
			Map<String, Loyalward> loyalwardMap = loyalwardFuture.get();
			Map<String, SalSocialAdjust> salSocialAdjustMap = salSocialAdjustFuture.get();
			Map<String, SalSalaryData> salSalaryDataMap = salSalaryDataFuture.get();
			Map<String, Solidmoney> solidmoneyMap = solidmoneyFuture.get();
			Map<String, Dutymoney> dutymoneyMap = dutymoneyFuture.get();
			Map<String, Bfsalary> bfsalaryMap = bfsalaryFuture.get();
			Map<String, Shiftallowance> shiftallowanceMap = shiftallowanceFuture.get();
			Map<String, Personalmoney> personalmoneyMap = personalmoneyFuture.get();
			Map<String, Secureunit> secureunitMap = secureunitFuture.get();
			Map<String, Dutysendmoney> dutysendmoneyMap = dutysendmoneyFuture.get();

			for (Uemp uemp : uempList) {
				SalarySumReport salarySumReport = new SalarySumReport();

				// Uemp
				// Entry<String,Uemp> uempEntry = uempIterator.next();
				// Uemp uemp = uempEntry.getValue();
				// 员工号
				String uempStaffint = uemp.getStaffint();
				// 工作地点
				//String workPlace = uemp.getWorkPlace();

				salarySumReport.setId(uemp.getDid());
				salarySumReport.setCard(uemp.getCard());
				salarySumReport.setStaffint(uemp.getStaffint());
				salarySumReport.setStaffname(uemp.getStaffname());
				salarySumReport.setDateentry(uemp.getDateentry());
				salarySumReport.setDatedimi(uemp.getDatedimi());
				salarySumReport.setDept(uemp.getDept());
				salarySumReport.setTean(uemp.getTean());
				salarySumReport.setCardlevel(uemp.getCardlevel());
				salarySumReport.setGrade(uemp.getGrade());
				salarySumReport.setJobgrade(uemp.getJobgrade());
				salarySumReport.setStafftypes(uemp.getStafftypes());
				salarySumReport.setJobsort(uemp.getJobsort());
				salarySumReport.setCommission(uemp.getCommission());
				salarySumReport.setAssailedcom(uemp.getAssailedcom());
				salarySumReport.setCostcentre(uemp.getCostcentre());
				salarySumReport.setStaffmoney(uemp.getMoneycount());

				// salarySumReport.setAccumuldan(getStringValue(uemp.getAccumuldan()));
				// salarySumReport.setNursingdan(getStringValue(uemp.getNursingdan()));
				// salarySumReport.setHealthdan(getStringValue(uemp.getHealthdan()));
				// salarySumReport.setUnempdan(getStringValue(uemp.getUnempdan()));
				// salarySumReport.setFirmsdan(getStringValue(uemp.getFirmsdan()));
				// salarySumReport.setFertilitydan(getStringValue(uemp.getFertilitydan()));

				// MinMoney FIXME
				MinMoney minMoney = minMoneyMap.get(uempStaffint);
				if (minMoney != null) {
					salarySumReport.setMinWage(minMoney.getMincount());
				}

				// Dispatchmanger
				Dispatchmanger dispatchmanger = dispatchmangerMap.get(uempStaffint);
				if (dispatchmanger != null) {
					salarySumReport.setDisAmountdou(dispatchmanger.getAmountdou());
				}
				// Overtimemoney
				Overtimemoney overtimemoney = overtimemoneyMap.get(uempStaffint);
				if (overtimemoney != null) {
					salarySumReport.setMoAmountdou(overtimemoney.getAmountdou());
				}
				// Overtimemeals
				Overtimemeals overtimemeals = overtimemealsMap.get(uempStaffint);
				if (overtimemeals != null) {
					salarySumReport.setMeAmountdou(overtimemeals.getAmountdou());
				}
				// Moneyadjust
				Moneyadjust moneyadjust = moneyadjustMap.get(uempStaffint);
				if (moneyadjust != null) {
					salarySumReport.setMonAmountdou(moneyadjust.getAmountdou());
				}
				// Tradecost
				Tradecost tradecost = tradecostMap.get(uempStaffint);
				if (tradecost != null) {
					salarySumReport.setTradecostdou(tradecost.getTradecostdou());
				}
				// Dutyback
				Dutyback dutyback = dutybackMap.get(uempStaffint);
				if (dutyback != null) {
					salarySumReport.setDbAmountdou(dutyback.getAmountdou());
				}
				// Personalduty
				Personalduty personalduty = personaldutyMap.get(uempStaffint);
				if (personalduty != null) {
					salarySumReport.setPerAmountdou(personalduty.getAmountdou());
				}
				// Leavebmoney
				Leavebmoney leavebmoney = leavebmoneyMap.get(uempStaffint);
				if (leavebmoney != null) {
					salarySumReport.setAmountsick(leavebmoney.getAmountsick());
					salarySumReport.setAmountthing(leavebmoney.getAmountthing());
					salarySumReport.setLmoAmountdou(leavebmoney.getAmountdou());
				}
				// Loyalward
				Loyalward loyalward = loyalwardMap.get(uempStaffint);
				if (loyalward != null) {
					salarySumReport.setLoyAmountdou(loyalward.getAmountdou());
				}
				// SalSocialAdjust
				SalSocialAdjust salSocialAdjust = salSocialAdjustMap.get(uempStaffint);
				if (salSocialAdjust != null) {
					salarySumReport.setAccumulUnitAdjust(salSocialAdjust.getAccumulUnitAdjust());
					salarySumReport.setNursingUnitAdjust(salSocialAdjust.getNursingUnitAdjust());
					salarySumReport.setHealthUnitAdjust(salSocialAdjust.getHealthUnitAdjust());
					salarySumReport.setUnempUnitAdjust(salSocialAdjust.getUnempUnitAdjust());
					salarySumReport.setFirmsUnitAdjust(salSocialAdjust.getFirmsUnitAdjust());
					salarySumReport.setFertilityUnitAdjust(salSocialAdjust.getFertilityUnitAdjust());
					salarySumReport.setDisabledAndOther(salSocialAdjust.getDisabledAndOther());
					salarySumReport.setAccumulPerAdjust(salSocialAdjust.getAccumulPerAdjust());
					salarySumReport.setNursingPerAdjust(salSocialAdjust.getNursingPerAdjust());
					salarySumReport.setHealthPerAdjust(salSocialAdjust.getHealthPerAdjust());
					salarySumReport.setUnempPerAdjust(salSocialAdjust.getUnempPerAdjust());
				}
				// SalSalaryData
				SalSalaryData salSalaryData = salSalaryDataMap.get(uempStaffint);
				if (salSalaryData != null) {
					salarySumReport.setPeriod(salSalaryData.getPeriod());
					salarySumReport.setMaternityPay(salSalaryData.getMaternityPay());
					salarySumReport.setMonthlyaward(salSalaryData.getMonthlyaward());
					salarySumReport.setHalfYearAwrad(salSalaryData.getHalfYearAwrad());
					salarySumReport.setYearawrad(salSalaryData.getYearawrad());
					salarySumReport.setDuyWrad(salSalaryData.getDuyWrad());
					salarySumReport.setIncenWrad(salSalaryData.getIncenWrad());
					salarySumReport.setAutoWrad(salSalaryData.getAutoWrad());
					salarySumReport.setCusWrad(salSalaryData.getCusWrad());
					salarySumReport.setCusicWrad(salSalaryData.getCusicWrad());
					salarySumReport.setCustyWrad(salSalaryData.getCustyWrad());
					salarySumReport.setCusapfWrad(salSalaryData.getCusapfWrad());
					salarySumReport.setCusthWrad(salSalaryData.getCusthWrad());
					salarySumReport.setCollWrad(salSalaryData.getCollWrad());
					salarySumReport.setCollthWrad(salSalaryData.getCollthWrad());
					salarySumReport.setDirectComm(salSalaryData.getDirectComm());
					salarySumReport.setDirethComm(salSalaryData.getDirethComm());
					salarySumReport.setDireperWrad(salSalaryData.getDireperWrad());
					salarySumReport.setDireamWrad(salSalaryData.getDireamWrad());
					salarySumReport.setDireanWrad(salSalaryData.getDireanWrad());
					salarySumReport.setDirethWrad(salSalaryData.getDirethWrad());
					salarySumReport.setHfisubWrad(salSalaryData.getHfisubWrad());
					salarySumReport.setHfishWrad(salSalaryData.getHfishWrad());
					salarySumReport.setHfiperWrad(salSalaryData.getHfiperWrad());
					salarySumReport.setHfiminWrad(salSalaryData.getHfiminWrad());
					salarySumReport.setHfisthWrad(salSalaryData.getHfisthWrad());
					salarySumReport.setBranchWrad(salSalaryData.getBranchWrad());
					salarySumReport.setBranptWrad(salSalaryData.getBranptWrad());
					salarySumReport.setBrancaWrad(salSalaryData.getBrancaWrad());
					salarySumReport.setBranhgWrad(salSalaryData.getBranhgWrad());
					salarySumReport.setBranthWrad(salSalaryData.getBranthWrad());
					salarySumReport.setBranqkWrad(salSalaryData.getBranqkWrad());
					salarySumReport.setBranfwWrad(salSalaryData.getBranfwWrad());
					salarySumReport.setBrandtlWrad(salSalaryData.getBrandtlWrad());
					salarySumReport.setBrandmaxWrad(salSalaryData.getBrandmaxWrad());
					salarySumReport.setBranswIwrad(salSalaryData.getBranswIwrad());
					salarySumReport.setBranofWrad(salSalaryData.getBranofWrad());
					salarySumReport.setBrancommWrad(salSalaryData.getBrancommWrad());
					salarySumReport.setBrantranWrad(salSalaryData.getBrantranWrad());
					salarySumReport.setBradpayWrad(salSalaryData.getBradpayWrad());
					salarySumReport.setBransupmhWrad(salSalaryData.getBransupmhWrad());
					salarySumReport.setBrandepWrad(salSalaryData.getBrandepWrad());
					salarySumReport.setBranperWrad(salSalaryData.getBranperWrad());
					salarySumReport.setBranatoWrad(salSalaryData.getBranatoWrad());
					salarySumReport.setBranoerWrad(salSalaryData.getBranoerWrad());
					salarySumReport.setBranextWrad(salSalaryData.getBranextWrad());
					salarySumReport.setBranriskWrad(salSalaryData.getBranriskWrad());
					salarySumReport.setNobrandWrad(salSalaryData.getNobrandWrad());
					salarySumReport.setBrandbitWrad(salSalaryData.getBrandbitWrad());
					salarySumReport.setOtherWrad(salSalaryData.getOtherWrad());
					salarySumReport.setEmicCoption(salSalaryData.getEmicCoption());
					salarySumReport.setParentsonly(salSalaryData.getParentsonly());
					salarySumReport.setAtaxAdsubit(salSalaryData.getDutydeduction());
					salarySumReport.setAnnualWageConvert(salSalaryData.getAnnualWageConvert());
					salarySumReport.setDutymeals(salSalaryData.getDutymeals());
					salarySumReport.setRecommWrad(salSalaryData.getRecommWrad());
					salarySumReport.setOncePreTaxBonus(salSalaryData.getDutygold());
					salarySumReport.setHighTemp(salSalaryData.getHighTemp());
					salarySumReport.setDutyadds(salSalaryData.getDutyadds());
					salarySumReport.setMainAll(salSalaryData.getMainAll());
					salarySumReport.setOtherAll(salSalaryData.getOtherAll());
					salarySumReport.setAfterbonus(salSalaryData.getAfterbonus());
				}
				// Solidmoney
				Solidmoney solidmoney = solidmoneyMap.get(uempStaffint);
				if (solidmoney != null) {
					salarySumReport.setMoneycount(solidmoney.getMoneycount());
					// salarySumReport.setDutycount(solidmoney.getDutysendmoney());
				}
				// Dutymoney
				Dutymoney dutymoney = dutymoneyMap.get(uempStaffint);
				if (dutymoney != null) {
					// salarySumReport.setMainAll(dutymoney.getMainAll());
					// salarySumReport.setOtherAll(dutymoney.getOtherAll());
					// salarySumReport.setHighTemp(dutymoney.getHightEmp());
					// salarySumReport.setRecommWrad(dutymoney.getRecommWrad());
					// salarySumReport.setDutycount(dutymoney.getDutycount());
					salarySumReport.setBfAmountdou(dutymoney.getBfmoney());

				}
				// Bfsalary
				Bfsalary bfsalary = bfsalaryMap.get(uempStaffint);
				if (bfsalary != null) {
					// salarySumReport.setBfAmountdou(bfsalary.getAmountdou());
				}
				// Shiftallowance
				Shiftallowance shiftallowance = shiftallowanceMap.get(uempStaffint);
				if (shiftallowance != null) {
					salarySumReport.setAmountmeals(shiftallowance.getAmountmeals());
					salarySumReport.setShiAmountdou(shiftallowance.getAmountdou());
				}
				// Personalmoney
				Personalmoney personalmoneyAccumulper = personalmoneyMap.get(uempStaffint + SalConstant.ACCUMUL_PER);
				Personalmoney personalmoneyNursingper = personalmoneyMap.get(uempStaffint + SalConstant.NURSING_PER);
				Personalmoney personalmoneyHealthper = personalmoneyMap.get(uempStaffint + SalConstant.HEALTH_PER);
				Personalmoney personalmoneyUnempper = personalmoneyMap.get(uempStaffint + SalConstant.UNEMP_PER);
				if (personalmoneyAccumulper != null) {
					salarySumReport.setAccumulper(personalmoneyAccumulper.getAmountdou());
				}
				if (personalmoneyAccumulper != null) {
					salarySumReport.setNursingper(personalmoneyNursingper.getAmountdou());
				}
				if (personalmoneyHealthper != null) {
					salarySumReport.setHealthper(personalmoneyHealthper.getAmountdou());
				}
				if (personalmoneyUnempper != null) {
					salarySumReport.setUnempper(personalmoneyUnempper.getAmountdou());
				}

				// Secureunit
				Secureunit secureunitAccumuldan = secureunitMap.get(uempStaffint + SalConstant.ACCUMUL_DAN);
				Secureunit secureunitNursingdan = secureunitMap.get(uempStaffint + SalConstant.NURSING_DAN);
				Secureunit secureunitHealthdan = secureunitMap.get(uempStaffint + SalConstant.HEALTH_DAN);
				Secureunit secureunitUnempdan = secureunitMap.get(uempStaffint + SalConstant.UNEMP_DAN);
				Secureunit secureunitFirmsdan = secureunitMap.get(uempStaffint + SalConstant.FIRMS_DAN);
				Secureunit secureunitFertilitydan = secureunitMap.get(uempStaffint + SalConstant.FERTILITY_DAN);

				if (secureunitAccumuldan != null) {
					salarySumReport.setAccumuldan(secureunitAccumuldan.getAmountdou());
				}
				if (secureunitNursingdan != null) {
					salarySumReport.setNursingdan(secureunitNursingdan.getAmountdou());
				}
				if (secureunitHealthdan != null) {
					salarySumReport.setHealthdan(secureunitHealthdan.getAmountdou());
				}
				if (secureunitUnempdan != null) {
					salarySumReport.setUnempdan(secureunitUnempdan.getAmountdou());
				}
				if (secureunitFirmsdan != null) {
					salarySumReport.setFirmsdan(secureunitFirmsdan.getAmountdou());
				}
				if (secureunitFertilitydan != null) {
					salarySumReport.setFertilitydan(secureunitFertilitydan.getAmountdou());
				}
				// Dutysendmoney
				Dutysendmoney dutysendmoney = dutysendmoneyMap.get(uempStaffint);
				if (dutysendmoney != null) {
					salarySumReport.setDutycount(dutysendmoney.getDutycount());
				}
				salarySumReportList.add(salarySumReport);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return salarySumReportList;
	}

	/**
	 * 根据传入的月份获取下一个月份
	 * 
	 * @param month
	 * @return
	 * @throws ParseException
	 */
	private String getNextMonth(String month) {
		String dateStr = null;
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
			Date date = sdf.parse(month);
			Calendar c = Calendar.getInstance();
			c.setTime(date);
			c.add(Calendar.MONTH, 1);
			dateStr = sdf.format(c.getTime());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return dateStr;
	}

}
